﻿using Ninject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Peninsula.DataAccess;
using Peninsula.DataAccess.EF;

namespace Peninsula.IOC
{
    /// <summary>
    /// 依赖解析器
    /// </summary>
    public class NinjectDependencyResolver : IDependencyResolver
    {
        private IKernel kernel;

        public NinjectDependencyResolver(IKernel kernelParm) {
            kernel = kernelParm;
            AddBind();
        }

        private void AddBind()
        {
            //throw new NotImplementedException();
            //  kernel.Bind<IProductRepository>().To<EFProductRepository>();
            // kernel.Bind<IAuthProvider>().To<FormsAuthProvider>();
            /*
                 #region 绑定 Repository
            kernel.Bind(typeof(IRepository<>)).To(typeof(EFBaseRepository<>)).InRequestScope();
            #endregion 绑定 Repository            
            */
           // kernel.Bind( typeof(IRepository<>)).To(typeof(BaseServicey<>));
        }

        public object GetService(Type serviceType)
        {
            return kernel.TryGet(serviceType);
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            return kernel.GetAll(serviceType);
        }
    }
}
